0

私は自分のコードをこのように書いています。

  function ftpsend()

  Dim vPath As String
  Dim vFile As String
  Dim vFTPServ As String
  Dim fNum As Long
  Dim currntdir As String

  currntdir = ThisWorkbook.Path & "\"


 vPath = currntdir
 vFile = currntdir & "abc.xml"
 vFTPServ = "ftp.abc.com" 

  'Mounting file command for ftp.exe
  fNum = FreeFile()
 Open vPath & "abc.txt" For Output As #fNum
 Print #1, "USER student" 
 Print #1, "xxxxx"
 Print #1, "send " & vFile  
 Print #1, "close" 
 Print #1, "quit" 
 Close


 Shell "ftp -n -i -g -s:" & vPath & "abc.txt  " & vFTPServ, vbNormalFocus

 end function 

これで、シェル コマンドはコンソール ftp.exe に出力を次のように表示します。

Connected to ftp.abc.com
220 Microsoft FTP service
ftp>USER student
230 User logged in 
ftp>send D:abc.xml
200 PORT command successful
226 Transfer Complete 
ftp>close
221>Good bye
ftp>

この出力をコンソールからテキスト ファイルにコピーしたいのですが、ユーザー名とパスワードが間違っていると、コンソールに「ユーザーがログインしていません」、「ログインに失敗しました」というメッセージが表示されることがあるため、処理したいそのエラー。ftp エラーを処理する他の方法はありますか? 助けてください...

前もって感謝します

4

1 に答える 1

0

交換してみる

Shell "ftp -n -i -g -s:" & vPath & "abc.txt  " & vFTPServ, vbNormalFocus

Shell "ftp -n -i -g -s:" & vPath & "abc.txt  " & vFTPServ & " > test.txt", vbNormalFocus

また

Shell "ftp -n -i -g -s:" & vPath & "abc.txt  " & vFTPServ & " >> test.txt", vbNormalFocus

>または>>コンソール出力をファイルに転送します。存在しない場合は >、との両方>>が作成されます。は既存の text.txt を削除し、新しい出力を の既存のコンテンツに追加します。test.txt>>>test.txt

于 2012-09-21T10:12:56.320 に答える