FTP files from Google App Engine
I was wondering if it was possible to FTP/SFTP a file from a Google App Engine application's servlet to a remote FTP/SFTP server. Or maybe by creating a Task on the TaskQueue... Has anyone got this?
The GAE's documentation says that "bytecode that attem开发者_运维技巧pts to open a socket or write to a file will throw a runtime exception"
Thank you for your time!
Sockets are now available on App Engine. You can use an ftp client library on App Engine but there is one caveat. Only passive mode will work. Also, in passive mode, sometimes the second connection will attempt to connect from a different IP address which some servers (like ftp.kernel.org) will ignore. If it fails, just try again, eventually you'll get the same IP address and the transfer will work.
YES it is possible! We use it to send CSV files from Google Cloud Storage to a third-party vendor that doesn't have any kind of REST/SOAP API into their system. Here is an example in Python:
from ftplib import FTP
import cloudstorage as gcs
# Connect to vendor FTP site
ftp = FTP('www.somevendor.com','vendorusername', 'vendormypassword')
# Move into the specific folder where you want to place the file
ftp.cwd('/path_to/target_folder')
# Set the file name
filename = 'my_csv_file.csv'
# Get the file you want to FTP from Google Cloud Storage
filepath = '/myapp.appspot.com/my_csv_file.csv'
# Open the file to prep for transfer
gcs_file = gcs.open(filepath,'r')
# Initiate the file transfer
ftp.storlines('STOR '+filename,gcs_file)
# Close the ftp connection
ftp.quit()
# Close the file
gcs_file.close()
return 'You are done...MONEY!!!'
The GAE's documentation says that "bytecode that attempts to open a socket or write to a file will throw a runtime exception"
If I am not wrong this pretty much rules out FTPing a file from GAE.
Here a Google employee confirms opening a port is not possible: http://groups.google.com/group/google-appengine/browse_thread/thread/21948f691660ca2/708036e7f2af595b?lnk=gst&q=ftp#708036e7f2af595b
But if you read carefully, he says opening a port to "listen on" in not allowed. You should give it a shot. I would love to hear from you the results of this experiment! :)
You can't open sockets - of any sort - on App Engine. All outgoing requests have to be over HTTP.
Following this link
https://cloud.google.com/appengine/docs/python/sockets/
one of the points under limitations and restrictions is
FTP is not supported
I'm having troubles with GAE using a different port for different packets, is the only work around for this to try multiple times until GAE uses the same port?
精彩评论