Jaimi
Jaimi

Reputation: 1

How do I upload multiple excel files to multiple FTP folders using python or VB?

I am needing to move about 40 excel spreadsheets to various folders on the FTP site(DAILY) based on excel file name.

For example if File1.xls then it will be moved to a directory's folder A if File2.xls then it will be moved to a directory's folder B and so forth.

So there are 40 files and 40 directories. Can someone please help me automate this in Python or VB?

I appreciate your help, Jaimi

Upvotes: 0

Views: 1492

Answers (2)

Sy Holloway
Sy Holloway

Reputation: 429

in VB.net try the following (it works in vb 2008):

My.Computer.Network.UploadFile("localfilename", "ftp server address", "username", "password")

Hope it helps and works (BTW , its my first time here so sorry if I did anything wrong)

Upvotes: 1

Daniel Hepper
Daniel Hepper

Reputation: 29967

Have a look at ftplib. Here is some untested code to get you started:

import ftplib

files = (
    # list your files and dirs here
    ('local_file1.xls', 'target_dir1'),
    ('local_file2.xls', 'target_dir2'),
    # etc.
)
ftp = ftplib.FTP("ftp://example.com")
ftp.login()
for filename, directory in files:
    f = open(f, 'rb')
    ftp.cwd(directory)
    ftp.storbinary("STOR %s"%filename, f)
    ftp.cwd('..')
    f.close()

Upvotes: 1

Related Questions