2009-12-26 48 views
4

我想知道是否有可能FTP/SFTP從谷歌App Engine應用程序的Servlet文件到遠程FTP/SFTP服務器。或者可以通過在TaskQueue上創建一個任務...有沒有人得到這個?FTP文件

的GAE的文檔中說,「字節碼試圖打開套接字或寫入到文件將拋出一個運行時異常」

謝謝您的時間!

+0

你想以編程方式做到這一點?否則,我認爲這屬於對superuser.com –

+2

@Lex,海報明確表示,他們希望從一個servlet做到這一點。這個問題屬於這裏。 –

回答

1

的GAE的文檔中說,「字節碼試圖打開套接字或寫入到文件將拋出一個運行時異常」

如果我沒看錯這個幾乎排除了FTP發佈從文件GAE。

這裏一個谷歌員工證實打開一個端口是不可能的:http://groups.google.com/group/google-appengine/browse_thread/thread/21948f691660ca2/708036e7f2af595b?lnk=gst&q=ftp#708036e7f2af595b

但是,如果你仔細看,他說,打開一個端口在不允許「監聽」。你應該試試看。我很樂意聽到你的這個實驗的結果! :)

+1

謝謝!我會盡快給它閱讀。 – Pablo

+0

不再是真的 - 套接字現在可用。 – Praxiteles

+0

是的,我的評論2009年有效。;-) – Sri

0

你不能打開插座 - 在App Engine上 - 任何形式的。所有傳出的請求必須通過HTTP。

+0

不再是真的 - ftp套接字現在可用:[python](https://developers.google.com/appengine/docs/python/sockets/),[java ](https://developers.google.com/appengine/docs/java/sockets/),[php](https://cloud.google.com/appengine/docs/php/sockets/)和[go] (https://cloud.google.com/appengine/docs/go/sockets/) – hyip

2

套接字現在可以在App Engine上。您可以在App Engine上使用ftp客戶端庫,但有一點需要注意。只有被動模式纔有效。另外,在被動模式下,有時第二個連接會嘗試從某個服務器(如ftp.kernel.org)將忽略的不同IP地址進行連接。如果失敗了,只需再試一次,最終你會得到相同的IP地址,並且傳輸將起作用。

+3

您使用哪個庫?嘗試commons-net,但由於白名單限制,它不起作用(javax.net.ServerSocketFactory) – Fabien

1

是的,它是可能的!我們使用它將CSV文件從Google Cloud Storage發送到第三方供應商,該供應商在其系統中沒有任何種類的REST/SOAP API。下面是在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!!!'