2012-01-27 5 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 
관련 문제