Python Forum
FTP File Download question / concern
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FTP File Download question / concern
#1
Im working on a small python file/script that will connect to our FTP server and look for 3 specific files and then download them to our network for processing.
when using the built in ftp functionality (ftplib) does that move the file off the server and onto our network? Or is it a simple "copy" that is occuring?

I ask because i have this code and after i run it and get my 3 files, when i try running it again, there are no files to get.. So i need to know if what i have written is literally moving the files off the server or are they being copied and i need to see if someone else has moved my files...


for fname in dlList:
    filesineed = [filename for filename in ftp.nlst() if fname in filename]
    # GET LISTING OF FILES
    files = ftp.nlst()
    for file in filesineed:   
        # CONCATENATED COMMAND AND FILENAME
        ftpcomm = ftpretr + file
        
        ftp.retrbinary(ftpcomm, open(file, 'wb').write)
Basically i just want to "copy" the 3 files i need leaving the originals in place on the ftp server for others to use..

Everything in my script has worked and didnt think nothing of it until i went to test my logic again and found that there are no files to download anymore.. so i need to make sure that i didnt move them and causing issues for my team.
Reply
#2
Really this question has more to do with your FTP server. But there's no reason that a FTP get/RETR (the retrbinary call) should cause the server to remove a file. I'd expect that you'd need a .delete() call (or at least a stor*() call to overwrite it), which isn't present.

So the program doesn't look suspicious or dangerous to the files on the FTP server to me.

Line 4 appears to be useless. It does another directory check but doesn't use the information.
Reply
#3
Yea line #4 was left behind when i was debugging and trying to see what files were actually on the server, there was a
print(files)
right below that line and i guess i forgot to delete that line as well when i pushed it to the test server.

I have a feeling someone moved the files after my initial testing this morning, but wanted to make sure that the code i had wasn't the cause of that.

new files are placed on the server every morning, so ill be testing again tomorrow morning to make sure that what i am doing is not the cause, but just needed someone to confirm the code was not causing it since I'm not very familiar with python.
Reply
#4
So i tested again this morning and everything went well.. got a hold of the person that actually uses the files that are pulled from the server and found out that he in fact deletes them off the server once he gets them onto the network, so it was not my code( at least not yet )

Now that i know he deletes them at the end, that will not be code that will be added to the script to handle once they are moved to our network.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FTP Download of Last File jland47 4 383 Mar-16-2024, 09:15 AM
Last Post: Pedroski55
  download a file from a URL JayManPython 7 1,341 Jun-28-2023, 07:52 AM
Last Post: JayManPython
  download with internet download manager coral_raha 0 2,941 Jul-18-2021, 03:11 PM
Last Post: coral_raha
  python application and credentials safety concern aster 4 3,490 Mar-06-2021, 06:51 PM
Last Post: snippsat
  download file from url fernandosianet 3 2,301 Oct-29-2020, 03:22 AM
Last Post: bowlofred
  Download file from Private GitHub rep vinuvt 0 1,968 Jul-27-2020, 11:38 AM
Last Post: vinuvt
  PyDrive download file path MiniMinnow 0 3,234 Apr-28-2020, 03:01 PM
Last Post: MiniMinnow
  download file from google drive .. evilcode1 7 13,814 Sep-21-2018, 06:13 PM
Last Post: evilcode1
  Download entire web pages and save them as html file with urllib.request fyec 2 14,680 Jul-13-2018, 10:12 AM
Last Post: Larz60+
  download dataset from SH file Felix 1 2,590 Mar-28-2018, 05:04 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020