-1

I'm attempting to use the ftplib library in Python to try and FTP some videos to my website. I've got a script with the basics "working", but there's a problem with it. When I try to play my video back using VLC player, it appears that it's corrupt, as it only plays the first 15 seconds of video (probably until some important keyframe in the video, but that's likely besides the point) and then the audio only sometimes continues.

The strange thing about it is that if I perform an ls -l on both the local directory and the remote directory, the filesizes are the same (even though the Mac locally calculates the filesize as 75.6 MB while the cPanel File Manager shows it as only 71.2 MB). To double-check, the MD5 checksums on both ends also came out to be the same. But clearly, the data isn't entirely right on the server side. Odds are, I'm probably not opening the .mov file correctly in my Python script, as it took me a little while just to wrap my head around file and file-like objects (meaning I probably still have it wrong).

This is my current upload script:

#!/usr/bin/env python

import os
from ftplib import FTP

# Log in to the FTP server
ftp = FTP('campusweatherservice.com')
ftp.login('myusername', 'mypassword')

# Change directories to the intended video source
os.chdir('/Users/cws/Desktop/CNET')

f = file('cnet.mov', 'rb')         # Currently opening the file as a file object
ftp.storbinary('STOR CNET.mov', f) # We then try to store it this way

# Close our file object and then quit the FTP client
f.close()
ftp.quit()

Any thoughts or obvious mistakes on my end here? If you'd like to try the video file for yourself, it's at http://www.campusweatherservice.com/CNET/CNET.mov

Devin
  • 996
  • 2
  • 8
  • 19
  • "the MD5 checksums on both ends also came out to be the same" -- then it's the same data (or you're lucky enough to find an MD5 collision :). Did you try playing the original file with the same player? – Anton Kovalenko Jan 14 '13 at 23:13
  • The original file did work. Unfortunately, there was one part to my testing that I didn't consider: downloading the file (that was uploaded to the FTP site) and playing it back locally in VLC (and even QuickTime too). Both of those worked fine. So I guess it's just an issue somewhere with streaming the file (either in the software or because of my web host). Oops! – Devin Jan 14 '13 at 23:25

1 Answers1

1

So hopefully you can see from the comments on the original question that this issue was a matter of testing, not the code.

Lessons learned here:

  1. If your checksums match, make damn sure your files aren't in fact, identical. That's 1000x more likely to be the case than some weird fringe case (as I originally figured it was)
  2. If you provide an actionable item in your Stack Overflow post (like 'download my video to see for yourself'), you should probably test that out yourself.

So I guess this question is now at least good as a) a reference for uploading files via FTP using Python and b) a good lesson on asking questions on Stack Overflow!

Devin
  • 996
  • 2
  • 8
  • 19