Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FTP file size
#1
Hi All,

Do you know a working solution to compare the remote file with the local file before downloading it from the ftp server?

I tried md5 hashing on both end but it is not supported via FTP, and I os.stat() or FTP.size(f) dont return the remote file's size either.
Reply
#2
Locally I prefer:
>>> import os
>>> s = os.path.getsize("C:/WinPEpge.sys")
>>> s
536870912


But idk about your FTP, you gave no intel on what libs and soft are you using there.
You could ie use python interpreter on remote host to calculate it via running cmd, then compare returned result to the file from your host. Also, I guess if you are using some python ftp lib, it has to be there something for checking object size in docs.
Reply
#3
You can try to get meta data Content-Length,to get size before download.
Now can it be that you need to log in to Ftp server then can use ftplib .
Example:
import requests

url = 'http://ipv4.download.thinkbroadband.com/50MB.zip'
size = requests.get(url, stream=True).headers['Content-length']
print(f'{size} Bytes == 50 Megabytes')
Output:
52428800 Bytes == 50 Megabytes
from ftplib import FTP

ftp = FTP('ftp.server')
ftp.login()
# ftp.size() returns file size in bytes
print(ftp.size('applications/data.zip'))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Converted EXE file size is too large Rajasekaran 0 1,511 Mar-30-2023, 11:50 AM
Last Post: Rajasekaran
  check if a file exist on the internet and get the size kucingkembar 6 1,760 Apr-16-2022, 05:09 PM
Last Post: kucingkembar
  How to extract MSS (maximum size segment) from a pcap file ? salwa17 0 1,678 Jun-29-2020, 09:06 AM
Last Post: salwa17
  Building a script to check size of file upon creation mightyn00b 2 2,385 Apr-04-2020, 04:39 AM
Last Post: Larz60+
  size of set vs size of dict zweb 0 2,142 Oct-11-2019, 01:32 AM
Last Post: zweb
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 6 24,059 Jun-19-2018, 03:43 PM
Last Post: JohnJSal
  CSV file created is huge in size. How to reduce the size? pramoddsrb 0 10,478 Apr-26-2018, 12:38 AM
Last Post: pramoddsrb

Forum Jump:

User Panel Messages

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