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

    Solved Copy file from Windows Server to hosted external CentOS server

    IT Discussion
    8
    29
    3.2k
    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.
    • T
      tiagom @JaredBusch
      last edited by

      @JaredBusch said in Copy file from Windows Server to hosted external CentOS server:

      @Tim_G said in Copy file from Windows Server to hosted external CentOS server:

      Excellent, definitely a few seeds planted for me to expand on.

      I'll check into WinSCP first to see if there's a way I can get things going.

      Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?

      Install it and make a connection. If it works, you can automate it easily.

      Here's a PS way to automate it.

      https://winscp.net/eng/docs/library_powershell#example

      JaredBuschJ 1 Reply Last reply Reply Quote 1
      • JaredBuschJ
        JaredBusch @tiagom
        last edited by

        @tiagom said in Copy file from Windows Server to hosted external CentOS server:

        @JaredBusch said in Copy file from Windows Server to hosted external CentOS server:

        @Tim_G said in Copy file from Windows Server to hosted external CentOS server:

        Excellent, definitely a few seeds planted for me to expand on.

        I'll check into WinSCP first to see if there's a way I can get things going.

        Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?

        Install it and make a connection. If it works, you can automate it easily.

        Here's a PS way to automate it.

        https://winscp.net/eng/docs/library_powershell#example

        Right, the developer of WinSCP made it very flexible.

        1 Reply Last reply Reply Quote 0
        • ObsolesceO
          Obsolesce @scottalanmiller
          last edited by

          @scottalanmiller said in Copy file from Windows Server to hosted external CentOS server:

          @Tim_G said in Copy file from Windows Server to hosted external CentOS server:

          Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?

          WinSCP is an SSH tool. SCP and SFTP are part of SSH. If you have SSH, you have SFTP.

          That's right. I was thinking FTPS... Two very different things.

          scottalanmillerS 1 Reply Last reply Reply Quote 0
          • GreyG
            Grey
            last edited by

            Or use something like dropbox, placing the file in the dropbox space on the server to sync, and then wget the file.

            1 Reply Last reply Reply Quote 0
            • scottalanmillerS
              scottalanmiller @Obsolesce
              last edited by

              @Tim_G said in Copy file from Windows Server to hosted external CentOS server:

              @scottalanmiller said in Copy file from Windows Server to hosted external CentOS server:

              @Tim_G said in Copy file from Windows Server to hosted external CentOS server:

              Note: There's not FTP access. ONLY SSH. WinSCP still a good place to start?

              WinSCP is an SSH tool. SCP and SFTP are part of SSH. If you have SSH, you have SFTP.

              That's right. I was thinking FTPS... Two very different things.

              Yup. Just a bit.
              Command line SCP or SFTP will work great here. Easy peasy and direct.

              1 Reply Last reply Reply Quote 2
              • ObsolesceO
                Obsolesce
                last edited by Obsolesce

                Update:

                I got it working cleanly and smoothly with WinSCP. Thanks for the pointer everyone!

                If anyone else who comes by this wants to know the procedure:

                • Download and install WinSCP on your Windows Server
                • Create a basic Scheduled Task, name it, schedule it --> "Start a program", browse to WinSCP.exe.
                • Use the argument:
                /log=C:\Users\<userProfile>\Desktop\<logName>.log /script=C:\Users\<userProfile>\Desktop\<scriptName>.txt
                
                • Open properties of Scheduled Task, change to run even if not logged in, run with highest privileges, click OK and enter password.

                Script Contents

                The <scriptName>.txt file can include what you need to happen. My use case was a simple one, and looked like this:

                # Connect
                open sftp://<username>:<password>@123.45.67.890 -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
                
                # Change remote directory
                cd /var/www/html/pki
                
                # Force binary mode transfer
                option transfer binary
                
                # Upload the files to current working directory
                put "D:\pki\<name>.html"
                put "D:\pki\<name>.crl"
                put "D:\pki\<name>+.crl"
                put "D:\pki\<name>.crl"
                put "D:\pki\<name>.crt"
                put "D:\pki\<name>.crt"
                
                # Disconnect
                close
                
                # Exit WinSCP
                exit
                

                Edit: Fixed formatting thanks to JaredBusch's advice below.

                JaredBuschJ 1 Reply Last reply Reply Quote 4
                • JaredBuschJ
                  JaredBusch @Obsolesce
                  last edited by JaredBusch

                  @Tim_G said in Copy file from Windows Server to hosted external CentOS server:

                  Note: The above pound symbols do not have a ' after them in the script. I added them on here to avoid formatting issues.

                  Use the code format by putting 3 backticks in front of and behind the code block. Or escape the # sign by puting a \ in front of it.

                  Click quote below this post to see it prefaced with > of course, but it lets you see what I mean.

                  # Connect
                  open sftp://<username>:<password>@123.45.67.890 -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
                  
                  # Change remote directory
                  cd /var/www/html/pki
                  
                  # Force binary mode transfer
                  option transfer binary
                  
                  # Upload the files to current working directory
                  put "D:\pki\<name>.html"
                  put "D:\pki\<name>.crl"
                  put "D:\pki\<name>+.crl"
                  put "D:\pki\<name>.crl"
                  put "D:\pki\<name>.crt"
                  put "D:\pki\<name>.crt"
                  
                  # Disconnect
                  close
                  
                  # Exit WinSCP
                  exit
                  

                  # Connect
                  open sftp://<username>:<password>@123.45.67.890 -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"

                  # Change remote directory
                  cd /var/www/html/pki

                  # Force binary mode transfer
                  option transfer binary

                  # Upload the files to current working directory
                  put "D:\pki<name>.html"
                  put "D:\pki<name>.crl"
                  put "D:\pki<name>+.crl"
                  put "D:\pki<name>.crl"
                  put "D:\pki<name>.crt"
                  put "D:\pki<name>.crt"

                  # Disconnect
                  close

                  # Exit WinSCP
                  exit

                  1 Reply Last reply Reply Quote 1
                  • AdamFA
                    AdamF
                    last edited by

                    I'm doing something very similar but cannot get the scheduled task to take my arguments properly.

                    I'm not sure where it is failing. Scheduled tasks gives no errors, just information.

                    The only difference is that my server listens on a port other than 22 for SSH. So, I put a :XXXX (port number) in the first command. Still no dice. I'm not sure if it is failing on the contents of the script, or failing because of the arguments.

                    # Connect
                    open sftp://<username>:<password>@123.45.67.890:XXXX -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
                    

                    The only info I get from event viewer is:

                    Task Scheduler successfully completed task "\Get Call Recordings" , instance "{13fcf873-f123-46e6-8e80-6ce90b57638c}" , action "C:\Program Files (x86)\WinSCP\WinSCP.exe" with return code 0.
                    1111
                    ObsolesceO 1 Reply Last reply Reply Quote 0
                    • ObsolesceO
                      Obsolesce @AdamF
                      last edited by

                      @fuznutz04 said in Copy file from Windows Server to hosted external CentOS server:

                      I'm doing something very similar but cannot get the scheduled task to take my arguments properly.

                      I'm not sure where it is failing. Scheduled tasks gives no errors, just information.

                      The only difference is that my server listens on a port other than 22 for SSH. So, I put a :XXXX (port number) in the first command. Still no dice. I'm not sure if it is failing on the contents of the script, or failing because of the arguments.

                      # Connect
                      open sftp://<username>:<password>@123.45.67.890:XXXX -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
                      

                      The only info I get from event viewer is:

                      Task Scheduler successfully completed task "\Get Call Recordings" , instance "{13fcf873-f123-46e6-8e80-6ce90b57638c}" , action "C:\Program Files (x86)\WinSCP\WinSCP.exe" with return code 0.
                      1111
                      

                      See if you can connect normally.

                      Open up a command prompt and run winscp.exe.

                      Then type just:

                      open sftp://<username>@123.45.67.890:XXXX -hostkey="ssh-rsa 2048 <hostkey>"
                      

                      If you can connect this way, by it prompting you to enter a username, then...

                      it might be that you may be using an unsupported character in your password... preventing you from including the password in the line you posted.

                      If the script actually runs, and you are using "/log=<path><log file>.log in the argument, you can check that log.

                      1 Reply Last reply Reply Quote 3
                      • AdamFA
                        AdamF
                        last edited by

                        So that works properly if I run it through command prompt. (meaning, it will open WinSCP and login successfully. ) However, for the scheduled task, it appears that it isnt even attempting to read that script.

                        Note: my password is all normal letters for this test.

                        ObsolesceO 1 Reply Last reply Reply Quote 0
                        • ObsolesceO
                          Obsolesce @AdamF
                          last edited by

                          @fuznutz04 said in Copy file from Windows Server to hosted external CentOS server:

                          So that works properly if I run it through command prompt. (meaning, it will open WinSCP and login successfully. ) However, for the scheduled task, it appears that it isnt even attempting to read that script.

                          Note: my password is all normal letters for this test.

                          What happens if you, in CMD enter in to a WinSCP.exe prompt, then you enter this:

                          open sftp://<username>:<password>@123.45.67.890:XXXX -hostkey="ssh-rsa 2048 <hostkey>"
                          

                          Does it connect then?

                          1 Reply Last reply Reply Quote 0
                          • ObsolesceO
                            Obsolesce
                            last edited by

                            Well we know that the scheduled task is successfully executing WinSCP.exe. That's a given due to the success message.

                            Now I'm trying to establish whether or not the script is running at all, by finding out if you can connect the same way the script is trying to connect. Using the username and password together when you connect. (as in my above post)

                            AdamFA 1 Reply Last reply Reply Quote 0
                            • AdamFA
                              AdamF @Obsolesce
                              last edited by

                              @Tim_G said in Copy file from Windows Server to hosted external CentOS server:

                              Well we know that the scheduled task is successfully executing WinSCP.exe. That's a given due to the success message.

                              Now I'm trying to establish whether or not the script is running at all, by finding out if you can connect the same way the script is trying to connect. Using the username and password together when you connect. (as in my above post)

                              So I was able to drop into a Winscp console via command prompt, and issue the

                              open sftp://<username>:<password>@123.45.67.890:XXXX -hostkey="ssh-rsa 2048 <hostkey>"
                              

                              command. Followed by all the other commands I need to make that are contained within the script. So it looks like the problem lies within Task scheduler actually launching the script.

                              ObsolesceO 1 Reply Last reply Reply Quote 0
                              • ObsolesceO
                                Obsolesce @AdamF
                                last edited by

                                @fuznutz04 said in Copy file from Windows Server to hosted external CentOS server:

                                @Tim_G said in Copy file from Windows Server to hosted external CentOS server:

                                Well we know that the scheduled task is successfully executing WinSCP.exe. That's a given due to the success message.

                                Now I'm trying to establish whether or not the script is running at all, by finding out if you can connect the same way the script is trying to connect. Using the username and password together when you connect. (as in my above post)

                                So I was able to drop into a Winscp console via command prompt, and issue the

                                open sftp://<username>:<password>@123.45.67.890:XXXX -hostkey="ssh-rsa 2048 <hostkey>"
                                

                                command. Followed by all the other commands I need to make that are contained within the script. So it looks like the problem lies within Task scheduler actually launching the script.

                                Okay, that leads me to believe you are running the task as a user that doesn't have permission to where the script lives.

                                AdamFA 1 Reply Last reply Reply Quote 0
                                • AdamFA
                                  AdamF @Obsolesce
                                  last edited by

                                  @Tim_G

                                  Just for testing, the Everyone group has full control of the directory and file of the script. The account being used is the Administrator account, which has full control. Task scheduler is open using "Run as Administrator" for good measure. Still no dice.

                                  ObsolesceO 1 Reply Last reply Reply Quote 0
                                  • ObsolesceO
                                    Obsolesce @AdamF
                                    last edited by

                                    @fuznutz04 said in Copy file from Windows Server to hosted external CentOS server:

                                    @Tim_G

                                    Just for testing, the Everyone group has full control of the directory and file of the script. The account being used is the Administrator account, which has full control. Task scheduler is open using "Run as Administrator" for good measure. Still no dice.

                                    I mean the task itself, within Task Scheduler.

                                    Like this:

                                    0_1486613478426_Untitled.jpg

                                    AdamFA 1 Reply Last reply Reply Quote 0
                                    • AdamFA
                                      AdamF @Obsolesce
                                      last edited by

                                      @Tim_G

                                      Yep, that's exactly how it's setup now.

                                      1 Reply Last reply Reply Quote 0
                                      • ObsolesceO
                                        Obsolesce
                                        last edited by

                                        What does the log file say?

                                        /log=C:\Users\<userProfile>\Desktop\<logName>.log /script=C:\Users\<userProfile>\Desktop\<scriptName>.txt
                                        

                                        In my case, the "Add arguments (optional):" field in the Action tab of the scheduled task is as above. It spits out a log file on the desktop. What does your log say?

                                        AdamFA 1 Reply Last reply Reply Quote 0
                                        • AdamFA
                                          AdamF @Obsolesce
                                          last edited by

                                          @Tim_G

                                          /log=C:\CallRecordingsTest\Winscp.log /script=C:\CallRecordingsTest\CallRecordings.txt

                                          OR,

                                          If I just have this: /log=C:\CallRecordingsTest\Winscp.log

                                          It will start WinSCP in the background (no GUI, I just know it's running via task manager) but will not put anything in the log file.

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