Hello, Thank you so much for making this wonderful video, this video is exactly what i was looking for. just few more doubts i have, i would really appreciate if you could respond. 1. is there any way we can copy/move files from one dir to another dir on ftp? 2. can we read the file on ftp before downloading (as per my requirement i need to check if file is relevant before downloading it). Thanks in advance, keep up the good work.
Hi, thanks for your appreciation 1. You can explore the rename command to move files remotely the FTP server ( docs.python.org/3/library/ftplib.html#ftplib.FTP.rename ) 2. You can read the contents of an FTP file into a variable using retrlines command as shown in the below example ( docs.python.org/3/library/ftplib.html#ftplib.FTP.retrlines ) lines = [] filename="abcd.txt" ftp.retrlines("RETR " + filename, lines.append) Hope this helps, Cheers👍
Thanku so much it helped a lot also can u please tell me if hostname is some IP address instead of localhost so can the code still works because I;m trying and it is showing me some error
Hi, using a hostname like "15.25.56.76" is valid. Please mention what error you are getting. You can also check if ssl is required. Also check the connectivity with winscp. Hope this helps Cheers 👍
Hi, I have found a solution at stackoverflow.com/a/29027386/2746323 If you want to find the timestamp of a single file, you can use ######################### code start timestamp = ftp.voidcmd("MDTM /remote/path/file.txt")[4:].strip() time = parser.parse(timestamp) ######################### code end If you want to find the timestamps of all the files in a remote folder, you can use ######################### code start from ftplib import FTP from dateutil import parser # ... (connection to FTP) files = ftp.mlsd("/remote/path") for file in files: name = file[0] timestamp = file[1]['modify'] time = parser.parse(timestamp) print(name + ' - ' + str(time)) ######################### code end Hope this helps Cheers👍
Hi, you can't directly copy folders to FTP. You can create a folder in the remote server using the ftp.mkd command and then copy all the files one by one. Hope this helps, cheers 👍
Hi, if you want to upload the contents of a whole folder, you can iterate through each file of the local folder using a for loop and upload each file using the storbinary function ( 09:38 ). If a file exists, it will be overwritten anyway. If you have nested folders, you have to ensure them in the remote location before uploading files in nested folders. Unfortunately, You have to implement the above algorithm yourself. If I find any implementation online, I will comment here Hope this helps, Cheers👍
Hi, there can be several approaches to solve this problem depending on the security considerations. You can host an FTP server at location A and host the files in the FTP folder, and copy that file to location B using a script in server B. Hope this helps, Cheers👍
Hi, use can use ftplib MLSD function to get the modified times along with filenames of all files in an FTP directory. Please see the solution in this link stackoverflow.com/a/29027386 Hope this helps, Cheers 👍
@@sn-op8oi Hi, then you can use ftp.dir command. The example code is present in the same stackoverflow post at stackoverflow.com/questions/29026709/how-to-get-ftp-files-modify-time-using-python-ftplib/29027386#29027386 Cheers 👍
Wasting almost half a day trying to access some ftp. u saved my life with the ssl command. Thank u so much!
You are welcome 👍
Sir, thank you so much for posting.this vid! I wasted 2 hours trying to get Paramiko and PySFTP to work, with no success.
Hi, thanks for the wonderful feedback 👍
Thank you for a great tutorial! You have a knack for explaining things in its simplest terms! Kudos sir!
Thanks for such a nice feedback👍
Hello, Thank you so much for making this wonderful video, this video is exactly what i was looking for.
just few more doubts i have, i would really appreciate if you could respond.
1. is there any way we can copy/move files from one dir to another dir on ftp?
2. can we read the file on ftp before downloading (as per my requirement i need to check if file is relevant before downloading it).
Thanks in advance, keep up the good work.
Hi, thanks for your appreciation
1. You can explore the rename command to move files remotely the FTP server ( docs.python.org/3/library/ftplib.html#ftplib.FTP.rename )
2. You can read the contents of an FTP file into a variable using retrlines command as shown in the below example ( docs.python.org/3/library/ftplib.html#ftplib.FTP.retrlines )
lines = []
filename="abcd.txt"
ftp.retrlines("RETR " + filename, lines.append)
Hope this helps, Cheers👍
Thanku so much it helped a lot also can u please tell me if hostname is some IP address instead of localhost so can the code still works because I;m trying and it is showing me some error
Hi, using a hostname like "15.25.56.76" is valid. Please mention what error you are getting. You can also check if ssl is required. Also check the connectivity with winscp.
Hope this helps
Cheers 👍
Thank you that was helpful
Thank u it was extremely helpful ,can u also provide a solution about how to find the timestamps of the files on ftp server
Hi, I have found a solution at stackoverflow.com/a/29027386/2746323
If you want to find the timestamp of a single file, you can use
######################### code start
timestamp = ftp.voidcmd("MDTM /remote/path/file.txt")[4:].strip()
time = parser.parse(timestamp)
######################### code end
If you want to find the timestamps of all the files in a remote folder, you can use
######################### code start
from ftplib import FTP
from dateutil import parser
# ... (connection to FTP)
files = ftp.mlsd("/remote/path")
for file in files:
name = file[0]
timestamp = file[1]['modify']
time = parser.parse(timestamp)
print(name + ' - ' + str(time))
######################### code end
Hope this helps
Cheers👍
Hello Sir, how can we copy folders over ftp?
Hi, you can't directly copy folders to FTP. You can create a folder in the remote server using the ftp.mkd command and then copy all the files one by one.
Hope this helps, cheers 👍
how to overwrite folders in ftp ?
Hi, if you want to upload the contents of a whole folder, you can iterate through each file of the local folder using a for loop and upload each file using the storbinary function ( 09:38 ). If a file exists, it will be overwritten anyway.
If you have nested folders, you have to ensure them in the remote location before uploading files in nested folders.
Unfortunately, You have to implement the above algorithm yourself. If I find any implementation online, I will comment here
Hope this helps, Cheers👍
thank you ur the best
Thanks for the awesome feedback 👍
Hi is there any process to send file from server location A to another server location B
Hi, there can be several approaches to solve this problem depending on the security considerations.
You can host an FTP server at location A and host the files in the FTP folder, and copy that file to location B using a script in server B.
Hope this helps, Cheers👍
hi iam getting erro:socket.timeout:timeout in ftp
Hi, this may be due to firewall policy blocking or network issues. Please check the firewall policy
Hope this helps, Cheers 👍
Thank you
Hi I need to download the names of those files which were uploaded in last 48 hours. How do I extract the time stamp and get those file names?
Hi, use can use ftplib MLSD function to get the modified times along with filenames of all files in an FTP directory. Please see the solution in this link stackoverflow.com/a/29027386
Hope this helps, Cheers 👍
@@learningsoftwareskills mlsd is blocked is there any other way?
@@sn-op8oi Hi, then you can use ftp.dir command. The example code is present in the same stackoverflow post at stackoverflow.com/questions/29026709/how-to-get-ftp-files-modify-time-using-python-ftplib/29027386#29027386
Cheers 👍
Gracias!!!
Thanks 👍
👍🏼
i awant to upload dir
Hi, you can use ftp.mkd to create a folder in the FTP server, then upload the files in the created folder.
Hope this helps, cheers 👍