Files uploaded to FTP server dont appear on the server

Advertisement

dwinn86
Joined:
Posts:
42
Location:
London

Files uploaded to FTP server dont appear on the server

Hello,

I have created a site in Visual Studio using VB.Net and ASP.Net that allows the upload and download of files to and from an FTP server via SFTP

I have produced the code, and my site allows a file to be uploaded via SFTP (WinSCP) but when I go on to the server, the files that I have uploaded do not appear to be there.

Here is my code:

If (mySession.Opened) Then

                transferOptions.TransferMode = TransferMode.Binary

                'transferResult = session.PutFiles(FileUpload1.ToString, "/", True, transferOptions)
                transferResult = mySession.PutFiles(LocalPath, RemotePath, False, transferOptions)

                ' Throw on any error 
                transferResult.Check()

            End If    

Can anybody please advise on whyt his is happening?

Many thanks

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
27,227
Location:
Prague, Czechia

Re: Files uploaded to FTP server dont appear on the server

Please set Session.SessionLogPath and attach a log file here.
_________________
Martin Prikryl

Reply with quote

dwinn86
Joined:
Posts:
42
Location:
London

Hi,

I do not appear to be getting a log file come out at all.

Here is my code:

Protected Function ProcessFiles() As String

        Dim Path As String
        Dim LocalPath As String
        Dim RemotePath As String
        Path = "C:\WinSCP\WinSCP.exe"
        LocalPath = "C:\" + FileUpload1.FileName
        'RemotePath = "ftp://user:password@xx.x.xx.xx/In/"

        Try
            ' Setup session options 
            Dim sessionOptions As New SessionOptions
            MsgBox("Processing")
            With sessionOptions
                .Protocol = Protocol.Sftp
                .HostName = "xx.xx.xx.xx"
                .PortNumber = 22
                .UserName = "user"
                .Password = "password"
                .SshHostKey = "ssh-rsa xxxx xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"

            End With

            'Set up the session 
            'Using session As Session = New Session
            Dim mySession As New Session
                ' Connect 

            mySession.ExecutablePath = Path

            mySession.Open(sessionOptions)
            Dim transferResult As TransferOperationResult

                ' Upload files 
            Dim transferOptions As New TransferOptions
                ' Print results 
            'Dim transfer As TransferEventArgs
            'For Each transfer In transferResult.Transfers
            'Console.WriteLine("Upload of {0} succeeded", transfer.FileName)
            'Console.Read()
            'Next

            If (mySession.Opened) Then

                transferOptions.TransferMode = TransferMode.Binary

                'transferResult = session.PutFiles(FileUpload1.ToString, "/", True, transferOptions)
                transferResult = mySession.PutFiles(LocalPath, RemotePath, False, transferOptions)

                ' Throw on any error 
                transferResult.Check()
                mySession.SessionLogPath = "c:\WinSCP\log.log"
            End If

            'End Using

            Return 0
        Catch e As Exception
            Console.WriteLine("Error: {0}", e)

            Return 1
        End Try

    End Function    

Any advice will be greatly apreciated.

Thanks

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,227
Location:
Prague, Czechia

You need to set that before calling Session.Open.
Otherwise, you should get an exception. Unless you are using an old version of WinSCP.
_________________
Martin Prikryl

Reply with quote

dwinn86
Joined:
Posts:
42
Location:
London

I put it to just before I open the session, and still not getting anything.

All I get is a page in IE after I try to upload the file, saying Internet explorer Cannot display the webpage.

I am using WinSCP 5.0.8 (Build 2438)

Reply with quote

dwinn86
Joined:
Posts:
42
Location:
London

Ok, I have managed to get a log file to be produced.

Can somebody please tell me what I should be looking for within this file?

Many thanks

Reply with quote

dwinn86
Joined:
Posts:
42
Location:
London

Hi,

I managed to sort this out.

I was connecting successfully via SFTP, but the way my PutFiles() method was implemented was wrong.

Thank you for all your help.

Reply with quote

Advertisement

You can post new topics in this forum