Topic "Newbie needing some help moving from Filezilla..."

Author Message
Galant
[View user's profile]

Joined: 2013-06-20
Posts: 2
Hi Guys,

Appreciate the assistance. I've recently taken over a project/client, part of which involves the automated daily transfer of a few files via FTP. Previously this had been done using Filezilla, however the client has been having problems with the automation and I've decided to ditch it and upon the recommendation of a friend use WinSCP.

I don't have a lot of experience on the scripting side of things, so although I think I've got the gist of things, I'm getting a little hung up on the nitty-gritty of it.

Since scripts already exist which had been used with Filezilla, I'm wondering if these will work. They're relatively simply, small scripts compared to others I've seen as examples, and so that's confusing me a bit.

There are two scripts:

1 - ftptransfer.txt
Login credentials, remote dir setup, multiple put and quit -

Code:
<username>
<password>
CD Outbox
ascii
prompt n
mput *.*
quit


2 - transfer.bat
Local Dir setp, Runs FTP based on other script creds, and archives the local files -

Code:
cd C:\Sales
ftp -s:C:\Sales\FTP_transfer\ftptransfer <ip address>
move *.* C:\Sales\Archive


Can those be used for the WinSCP script or should I start fresh?


I found this example and modified it, is it all necessary/correct?

Code:

[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null
 
   
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::ftp
    $sessionOptions.HostName = "<IP address>"
    $sessionOptions.UserName = "<username>"
    $sessionOptions.Password = "<password>"
    $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
 
    $session = New-Object WinSCP.Session
 
        $session.Open($sessionOptions)
 
        $localPath = "C:\Sales\"
        $remotePath = "/Gibraltar/Outbox"
        $backupPath = "C:\Sales\Archive"
 
        $transferResult = $session.PutFiles($localPath, $remotePath)
 
        # Iterate over every transfer
        foreach ($transfer in $transferResult.Transfers)
        {
            # Success or error?
            if ($transfer.Error -eq $Null)
            {
                Write-Host ("Upload of {0} succeeded, moving to backup" -f
                    $transfer.FileName)
                # Upload succeeded, move source file to backup
                Move-Item $transfer.FileName $backupPath
            }
            else
            {
                Write-Host ("Upload of {0} failed: {1}" -f
                    $transfer.FileName, $transfer.Error.Message)
            }
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch [Exception]
{
    Write-Host $_.Exception.Message
    exit 1
}


Thanks,

G.
Galant
[View user's profile]

Joined: 2013-06-20
Posts: 2
Hi there, can no-one assist me with this?

A.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24994
Location: Prague, Czechia
First: The existing script is no way Filezilla script. Filezilla does not support scripting at all. The script seems like for Windows built-in command-line FTP client.

Second: The reason the exiting script is short comparing your your new is, that the new "script" is not really a WinSCP script, but full Powershell application that uses WinSCP .NET assembly. Although it is definitely a solution, for such a simple tasks, you can do with simple WinSCP scripting that would involve as little lines as the original script:
https://winscp.net/eng/docs/guide_automation

To finally answer your question: It would be better if you describe any issues you may have. Note that we do not provide code review service here.

Anyway, I can see two issues:
- You are missing slash after /Gibraltar/Outbox
- You do not set an ascii mode (WinSCP defaults to binary mode).
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License