ML
    • Register
    • Login
    • Search
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

    PowerShell - FTP Upload Script No Longer Working

    IT Discussion
    powershell ftp script
    5
    31
    1095
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • wrx7m
      wrx7m last edited by wrx7m

      I have the following FTP upload script that stopped working after a server migration and IP change.

      $File = "D:\Data\BAUPC.CSV"
      $ftp = "ftp://user.name:[email protected]/BAUPC.CSV"
      
      "ftp url: $ftp"
      
      $webclient = New-Object System.Net.WebClient
      $uri = New-Object System.Uri($ftp)
      
      "Uploading $File..."
      
      $webclient.UploadFile($uri, $File)
      

      It was run on a schedule to upload a csv file to a web server. I changed the IP address (obviously, not the one above). The username is now in a [email protected] syntax. After updating credentials, I get a 530 error (not logged in).

      I am guessing it no longer likes the username and password as part of the URL. Any suggestions on how to modify this script?

      And yes, I did verify that the settings work in FileZilla (I did have to change it to Only use plain FTP).

      1 Reply Last reply Reply Quote 2
      • JaredBusch
        JaredBusch last edited by

        Did the password change? Do you have special character in it?

        wrx7m 1 Reply Last reply Reply Quote 1
        • JaredBusch
          JaredBusch last edited by JaredBusch

          That said, I have never had good luck with the System.Net.WebClient back when I was developing.

          I ended up getting the dll from this and doing things.
          https://winscp.net/eng/index.php

          1 Reply Last reply Reply Quote 2
          • wrx7m
            wrx7m @JaredBusch last edited by

            @JaredBusch Yes, password changed. Only alphanumeric.

            1 Reply Last reply Reply Quote 0
            • dafyre
              dafyre last edited by

              If the username has an @ symbol in it, wouldn't he have to escape that?

              M 1 Reply Last reply Reply Quote 0
              • M
                manxam @dafyre last edited by

                @dafyre, I would have thought so because the @ is used for here-strings but powershell seems fine with them:

                PS C:\Users\manxam> $test = "@"
                PS C:\Users\manxam> echo $test
                @
                PS C:\Users\manxam> $test2 = '@'
                PS C:\Users\manxam> echo $test2
                @
                
                JaredBusch 1 Reply Last reply Reply Quote 0
                • JaredBusch
                  JaredBusch @manxam last edited by

                  @manxam said in PowerShell - FTP Upload Script No Longer Working:

                  @dafyre, I would have thought so because the @ is used for here-strings but powershell seems fine with them:

                  PS C:\Users\manxam> $test = "@"
                  PS C:\Users\manxam> echo $test
                  @
                  PS C:\Users\manxam> $test2 = '@'
                  PS C:\Users\manxam> echo $test2
                  @
                  

                  But it is not powershell. it is System.Net.WebClient that is using it.

                  1 Reply Last reply Reply Quote 0
                  • wrx7m
                    wrx7m last edited by

                    I am trying a winscp script. Haven't gotten in correct yet.

                    1 Reply Last reply Reply Quote 0
                    • wrx7m
                      wrx7m last edited by

                      WinSCP doesn't like [email protected] syntax for the username either. WTF

                      JaredBusch 1 Reply Last reply Reply Quote 0
                      • dafyre
                        dafyre last edited by

                        What version of Windows does this run on?

                        When i try to run it (Windows 10), it crashes on the $uri line.

                        wrx7m 1 Reply Last reply Reply Quote 0
                        • wrx7m
                          wrx7m @dafyre last edited by wrx7m

                          @dafyre said in PowerShell - FTP Upload Script No Longer Working:

                          What version of Windows does this run on?

                          When i try to run it (Windows 10), it crashes on the $uri line.

                          Server 2012 R2 (is where the FTP client/script is running)

                          1 Reply Last reply Reply Quote 0
                          • JaredBusch
                            JaredBusch @wrx7m last edited by

                            @wrx7m said in PowerShell - FTP Upload Script No Longer Working:

                            WinSCP doesn't like [email protected] syntax for the username either. WTF

                            because it is smarter and has credential variables to be supplied.

                            wrx7m 1 Reply Last reply Reply Quote 0
                            • wrx7m
                              wrx7m @JaredBusch last edited by

                              @JaredBusch So it looks like I will have to use url-encoding. However, I can't get this to work either.
                              https://winscp.net/eng/docs/session_url

                              Pete.S 1 Reply Last reply Reply Quote 0
                              • Pete.S
                                Pete.S @wrx7m last edited by Pete.S

                                @wrx7m Why don't you just use the (built-in) ftp client in windows?

                                ftp -s:filename_with_ftp_commands

                                Run whatever commands you need for instance:

                                open 10.43.0.0
                                [email protected]
                                user_password
                                put D:\Data\BAUPC.CSV /BAUPC.CSV
                                bye
                                

                                Do it manually first so you know it works then just put the commands in the file.

                                PS. Here is a list of the command in the built-in windows ftp client. https://www.nsftools.com/tips/MSFTP.htm

                                wrx7m 2 Replies Last reply Reply Quote 0
                                • wrx7m
                                  wrx7m @Pete.S last edited by

                                  @Pete-S I used to have that setup, but there was something that happened where it got deprecated or something like that. can't remember now. It was a couple of years ago. I will try it again.

                                  1 Reply Last reply Reply Quote 0
                                  • wrx7m
                                    wrx7m @Pete.S last edited by

                                    @Pete-S it still gives login incorrect

                                    Pete.S 1 Reply Last reply Reply Quote 0
                                    • Pete.S
                                      Pete.S @wrx7m last edited by Pete.S

                                      @wrx7m said in PowerShell - FTP Upload Script No Longer Working:

                                      @Pete-S it still gives login incorrect

                                      Then you probably made a mistake somewhere.
                                      Login works here with a username in the format [email protected]. Win7 client connecting to linux ftp server.
                                      So it's not the windows ftp client that is the problem.

                                      Pete.S 1 Reply Last reply Reply Quote 0
                                      • Pete.S
                                        Pete.S @Pete.S last edited by Pete.S

                                        It could be that the server is requiring a SSL/TLS connection.

                                        Then it would connect over normal FTP but switch to encryption before sending username/password. But then all firewall rules and whatnot have to be set right and the client also has to support TLS for it to work.

                                        Is it a windows server you sending the file to? Then check what ftp server settings it has.

                                        1 Reply Last reply Reply Quote 0
                                        • dafyre
                                          dafyre last edited by

                                          I tried using this on a local FTP server that I control using known usernames and passwords....

                                          using user.name / MySecretPassword! works fine.

                                          using [email protected] / MySecretPassword! does not work at all -- with the ftp command line, nor the .Net.Webclient for me.

                                          1 Reply Last reply Reply Quote 1
                                          • wrx7m
                                            wrx7m last edited by

                                            @Pete-S said in PowerShell - FTP Upload Script No Longer Working:

                                            @wrx7m said in PowerShell - FTP Upload Script No Longer Working:

                                            @Pete-S it still gives login incorrect

                                            Then you probably made a mistake somewhere.
                                            Login works here with a username in the format [email protected]. Win7 client connecting to linux ftp server.
                                            So it's not the windows ftp client that is the problem.

                                            The server is running ProFTPD. It is not running encryption, because I had to disable encryption in Filezilla in order to connect.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post