0

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

2 Answers 2

1

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()
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your help. I am getting the following error: "TypeError: Coercing to Unicode: Need string or Buffer, Tuple found"
It's difficult to answer without more information. Can you post your code and the full error?
from ftplib import FTP ftp = FTP(www.ftp.com) # connect to host, default port directory = ('ATNET') files = ( ('1121_Score_Card.xls', '/ATNET/ls0931/FROMLS'), ('1122_Score_Card.xls', '/ATNET/ls1674/FROMLS'), ('1123_Score_Card.xls', '/ATNET/ls5738/FROMLS'), ('1124_Score_Card.xls', '/ATNET/ls1476/FROMLS') ) for filename, directory in files: f = open(files, 'rb') ftp.cwd(directory) ftp.storbinary("STOR %s"%filename, files) ftp.cwd('..') files.close() #ftp.quit()
1

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)

1 Comment

if its a form then either in form_load button_click, if its a console then just plonk it in the main sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.