Transfer a file in Local folder to a folder in FTP server and rename
I need to upload a file start with a specified string (0001) to an FTP server
My code it's working Only if give it the full filename = 0001_2655545XXXX
I need to upload a file if it is start with a string (0001) Without specifying the full name
I need to upload a file start with a specified string (0001) to an FTP server
My code it's working Only if give it the full filename = 0001_2655545XXXX
I need to upload a file if it is start with a string (0001) Without specifying the full name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import os, sys, stat import ftplib from ftplib import FTP def ftpPush(src, filename , dst, new_name): ftp = FTP( 'xxxxxx' , user = 'xxx' , passwd = 'xxxx' ) ftp.cwd(dst) ftp.storlines( "STOR " + filename, open (src + filename, 'rb' )) ftp.rename(filename, new_name) ftp.quit() src = '/' #path local dst = '//' #path server FTP new_name = "Test1" filename = [] for fileName in os.listdir(src): if filename.startswith( '0001' ): ftpPush(src, filename, dst, new_name) print ( "File uploaded and renamed successfully!" ) |