2012-01-27 12 views
0

私はFTPサーバー上にフォルダを作成するために次のコードを使用しています。しかし、その私の場合には動作しない: -FTPサーバーにディレクトリを作成する方法

  Dim sFilePath as string =filepath 
      Dim ftpResponse1 As FtpWebResponse 
      Dim ftpRequest1 As FtpWebRequest 
      Dim IsExists1 As Boolean = True 
      ftpRequest1 = CType(FtpWebRequest.Create(sFilePath), FtpWebRequest) 
      ftpRequest1.UseBinary = True 
      ftpRequest1.Credentials = New NetworkCredential(ZXFTPUSER, ZXFTPPASS) 
      ftpRequest1.UsePassive = True 
      ftpRequest1.Method = WebRequestMethods.Ftp.MakeDirectory 
      'ftpRequest1.KeepAlive = False 
      'ftpResponse1 = ftpRequest1.GetResponse() 

      'ftpResponse1 = ftpRequest1.GetResponse() 
      'Dim strstream1 As Stream = ftpResponse1.GetResponseStream() 
      'Dim strreader1 As New StreamReader(strstream1) 
      'Console.WriteLine(strreader1.ReadToEnd()) 
      'strreader1.Close() 
      'strstream1.Close() 
      'ftpResponse1.Close() 

私を助けてください。

は、上記のケースで、私はすべてのエラーを取得していないが、私は、RARファイルをアップロードしようと思ってたときに、それは次の例外に

を与えているリモートサーバーがエラーを返しました:(550)が利用できないファイル(例: 、ファイルが見つかりません、アクセスなし)。

とファイルアップロードコードは様々なサイトを通じて探し

Public Sub FTPUpload(ByVal SourceFile() As IO.FileInfo, ByVal folderLevel As Integer, ByVal ftpPassiveMode As Boolean) 
      ZXFTPPASS = "******" 
      Dim filePath As New IO.DirectoryInfo(filePaths) 
      Dim ftpRequest As FtpWebRequest 
      Dim dResult As Windows.Forms.DialogResult 
      Dim ftpFilePath As String = "" 
      Dim levelPath As String = "" 
      Dim iLoop As Integer 
      Dim uFile As IO.FileInfo 

      For Each uFile In SourceFile 
       Try 
        ftpFilePath = levelPath & "/" & uFile.Name 
        ftpRequest = CType(FtpWebRequest.Create(ftpFilePath), FtpWebRequest) 

        ftpRequest.Credentials = New NetworkCredential(ZXFTPUSER, ZXFTPPASS) 
        ftpRequest.UsePassive = ftpPassiveMode 
        ftpRequest.UseBinary = True 
        ftpRequest.KeepAlive = False 
        ftpRequest.Method = WebRequestMethods.Ftp.UploadFile 
        'Read in the file 
        Dim b_file() As Byte = System.IO.File.ReadAllBytes(filePath.FullName & "\" & uFile.Name.ToString()) 

        'Upload the file 
        Dim cls_stream As Stream = ftpRequest.GetRequestStream() 
        cls_stream.Write(b_file, 0, b_file.Length) 
        cls_stream.Close() 
        cls_stream.Dispose() 

        'MsgBox("Uploaded Successfully", MsgBoxStyle.Information) 
       Catch 
        MsgBox("Failed to upload.Please check the ftp settings", MsgBoxStyle.Critical) 
       End Try 
      Next 
     End Sub 
+0

エラーの説明とは何ですか? – adatapost

答えて

4

以下の通りである私が発見したこの:

Private Function FtpFolderCreate(folder_name As String, username As String, password As String) As Boolean 
    Dim request As Net.FtpWebRequest = CType(FtpWebRequest.Create(folder_name), FtpWebRequest) 
    request.Credentials = New NetworkCredential(username, password) 
    request.Method = WebRequestMethods.Ftp.MakeDirectory 

    Try 
     Using response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse) 
      ' Folder created 
     End Using 
    Catch ex As WebException 
     Dim response As FtpWebResponse = DirectCast(ex.Response, FtpWebResponse) 
     ' an error occurred 
     If response.StatusCode = FtpStatusCode.ActionNotTakenFileUnavailable Then 
      Return False 
     End If 
    End Try 
    Return True 
End Function 
関連する問題