[Solved] Bat File Uploading CSV via FTP - Works from Server 2008 R2, 0KB File on FTP from 2012 R2

  • I have a strange issue. We recently migrated our ERP from a Windows Server 2008 R2 VM to a 2012 R2 VM. We have a scheduled task that runs a bat file using powershell (calling old school built-in Windows FTP client) to upload a CSV file (that the ERP software generates) to our website server via FTP.

    Ever since we migrated, it hasn't properly updated the site. Upon further inspection, I can see that the file is only created/named on the FTP side and is 0KB. I have tested the bat file manually, by doing a run as administrator and it does the same thing.

    I went back and verified the old server is still working fine. I am wondering if there has been a change in the way that powershell handles it. I didn't create the bat file, the VAR for our ERP solution did it a couple of years ago.

    Here is the breakdown. Does anyone know why this doesn't work on 2012 R2?

    Bat file contents-

    powershell ftp -s:C:\ps\FTP\NightlyFTP.txt

    NightlyFTP.txt contents-

    put D:\Data\FTP.CSV

  • I ended up going with an upgraded script by truly using powershell.

    I found the answer here -

    Essentially this is the script:

    $File = "D:\Dev\somefilename.zip"
    $ftp = "ftp://username:[email protected]/pub/incoming/somefilename.zip"

    "ftp url: $ftp"

    $webclient = New-Object System.Net.WebClient
    $uri = New-Object System.Uri($ftp)

    "Uploading $File..."

    $webclient.UploadFile($uri, $File)