<|im_start|>system
You are a helpful AI assistant.<|im_end|>
<|im_start|>user
Write python code to connect to a FTP server.<|im_end|>
<|im_start|>assistant
To connect to an FTP server in Python, you can use the built-in ftplib module. Here is an example function that connects to an FTP server:

```
import ftplib

def ftp_connect(host, username, password):
    ftp = ftplib.FTP(host)
    ftp.login(username, password)
    return ftp
```

In this function, host is the hostname or IP address of the FTP server, username and password are the login credentials for the FTP server. The ftp.login() method is used to authenticate the user with the FTP server. The function returns the FTP object, which can be used to perform operations on the FTP server, such as uploading or downloading files.

Here's an example of how to use this function to connect to an FTP server:

```
ftp = ftp_connect('ftp.example.com', 'username', 'password')
print(ftp.getwelcome())  # prints the welcome message from the FTP server
ftp.quit()  # disconnects from the FTP server
```

In this example, ftp.example.com is the hostname of the FTP server, and username and password are the login credentials. The ftp.getwelcome() method is used to print the welcome message from the FTP server. The ftp.quit() method is used to disconnect from the FTP server.<|im_end|>
<|im_start|>user
That's a good start, and now, I need to recursively list all files and save their paths and sizes to a pandas dataframe, please.<|im_end|>
<|im_start|>assistant
Sure thing! Here's the updated code that recursively lists all files on the FTP server and saves their paths and sizes to a pandas dataframe:

```python
from ftplib import FTP
import getpass
import pandas as pd

# IP address for FTP server
myhost = '127.0.0.1' 

def get_files(ftp, path="", files=[]):
    """
    Recursively list all files on an FTP server.
    """
    ftp.cwd(path)
    
    try:
        dirs = ftp.nlst()
        
        for dir in dirs:
            if "." not in dir:
                get_files(ftp, path + "/" + dir, files)
                
    except Exception as e:
        files.append({"path": path, "size": ftp.size(path)})
        
    return files

with FTP(myhost) as ftp:
    
    username = input('Enter username: ')
    password = getpass.getpass('Enter password: ')
    
    ftp.login(username, password)
    
    # Get all file paths and sizes recursively from the root directory
    file_list = get_files(ftp)

# Create a pandas dataframe with the file paths and sizes
df = pd.DataFrame(file_list)

print(df.head())
```

This should print out a dataframe with two columns: "path" (the full path of each file) and "size" (the size of each file). Let me know if you have any questions!<|im_end|>