2012-01-27 29 views
1

我使用Net :: FTP將文件傳輸到大型機,並且正在測試失敗情況。來自Perl Net :: FTP的錯誤原因

我的代碼基本上是大致如下:

my $ftp = Net::FTP->new ("mainframe.com", Timeout => 20); 
    if (! $ftp) { 
      logMessage ("Could not connect to host: $!"); 
      return; 
    } 

    if (! $ftp->login ("paxdiablo", "demigodemporeroftheuniverse")) { 
      logMessage ("Could not log in to host: $!"); 
      $ftp->quit(); 
      return; 
    } 

    if (! $ftp->put ("myfile.txt", "'CANT.WRITE.TO.THIS'")) { 
      logMessage ("Could not put file: $!"); 
      $ftp->quit(); 
      return; 
    } 

知道我不能創建數據集CANT.WRITE.TO.THIS因爲我沒有必要的權限,但是,當我嘗試,唯一的我看到的消息是:

Could not put file: 

$!沒有跡象表明問題是什麼。我看着在Net::FTP doco和所有它說的是:

put (LOCAL_FILE [, REMOTE_FILE ])

Put a file on the remote server. LOCAL_FILE may be a name or a filehandle. If LOCAL_FILE is a filehandle then REMOTE_FILE must be specified. If REMOTE_FILE is not specified then the file will be stored in the current directory with the same leafname as LOCAL_FILE.

Returns REMOTE_FILE or the generated remote filename if REMOTE_FILE is not given.

我也找不到任何有關於檢索特定錯誤(如$ftp->getLastError()什麼類似)。

我該如何向用戶註明爲什麼的傳輸失敗?

在較早的迭代中,我採取了放置文件,然後再次獲取並在本地檢查內容。我真的寧願不是不得不再次對人們造成這樣的代碼。

+0

你可以通過FTP服務器提交一個小的工作,試圖創建數據集CANT.WRITE.TO.THIS。然後解析JESLOG中的RACF或ACF2消息,指出更具體的錯誤。 – 2012-01-30 03:53:11

回答

4

Net::FTP

$ftp = Net::FTP->new("some.host.name", Debug => 0) 
    or die "Cannot connect to some.host.name: [email protected]" 

[email protected]

$ftp->cwd("/pub") 
    or die "Cannot change working directory ", $ftp->message; 

$ftp->message

+0

Aarrgghh!愚蠢的doco。在實際的描述部分沒有提到message(),只是在示例代碼中。我從Net :: Cmd中看到,它來自那裏,但它確實應該聲明它繼承了什麼 - 我注意到它似乎沒有給你例如代碼()。儘管如此,那不是你的錯,而且你幫了很多忙,所以+1並且接受。 – paxdiablo 2012-01-27 06:42:53

相關問題