I recently had the problem that I could not pass my FTP object into a module that I had written myself.
The problem was that every time I had to reconnect to the FTP server and lost a lot of time.
Passing variables
Let’s say we have two Python script files. One of these is just the main script and the second file is check.py
The check.py is located in a subfolder called lib and is imported from there into my main script.
If we do that, the main script variables will not automatically be present in check.py. However, you can simply pass these by executing the following …
...
...
from lib import check
check.ftp_obj = ftp_obj
myCoolFuntion('some_file.css')
...
...
def myCoolFuntion(file):
ftp_datetime = ftp_obj.voidcmd("MDTM " + file)[4:].strip()
ftp_timestamp = time.mktime(time.strptime(ftp_datetime, '%Y%m%d%H%M%S'))
print(int(ftp_timestamp))
Summary
With this method you can pass on as many variables as you like to another script. I used that with my ftp object and it worked as well. Have fun with it!