Author Topic: Need to understand how to send and delete files on a VPS  (Read 4701 times)

0 Members and 1 Guest are viewing this topic.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Need to understand how to send and delete files on a VPS
« on: August 03, 2019, 01:39:10 pm »
Hi guys! I'm back.

I need to know 2 things: how can I upload a file to a VPS, and how to delete it later. I already know how to download a file, which is fairly simple as it doesn't require anything special with login and password, but in the case of upload and delete, it's a bit more complicated. How's it done?

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Need to understand how to send and delete files on a VPS
« Reply #1 on: August 03, 2019, 02:17:11 pm »
I have PuTTY here, so it allows me to use pscp.exe but I can't call it from a QB64 program because the command only contains the user info, not the password, which is asked later. I don't know if it's possible to send a one-line command where everything is included. Something like this pseudo code:

SEND file.txt TO user:password@120.60.30.15:/remote_folder

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Need to understand how to send and delete files on a VPS
« Reply #2 on: August 03, 2019, 02:36:10 pm »
I have PuTTY here, so it allows me to use pscp.exe but I can't call it from a QB64 program because the command only contains the user info, not the password, which is asked later. I don't know if it's possible to send a one-line command where everything is included. Something like this pseudo code:

SEND file.txt TO user:password@120.60.30.15:/remote_folder

Isn’t it a case of:

putty.exe mylogin@somewhere.com -pw mypassword

OR

putty.exe somewhere.com -l mylogin -pw mypassword


If you want to connect using SSH, use this:

putty.exe -ssh root@somewhere.com -pw mypasswordforsomewherecom
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Need to understand how to send and delete files on a VPS
« Reply #3 on: August 03, 2019, 02:46:38 pm »
pscp -pw yourPasswordHere C:\Users\testUser\Downloads\test.sh testUser@123.123.123.123:/home/testUser

pscp -pw (your password) (FILE) (WHERE) — as indicated above
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Need to understand how to send and delete files on a VPS
« Reply #4 on: August 03, 2019, 02:47:49 pm »
Hi Sam,

The examples you showed bring up the PuTTY console already logged to the VPS. I should then manually type a command to send the desired file to the VPS. What I want is a way to automatically send a file from my PC to the VPS, preferably without having to open the console, just in a single line if at all possible. My plan is to include such line inside my QB64 program.

I already have a QB64 program that regularly downloads a file that contains progress and status of an ongoing task being performed in a VPS (it's written in PHP and JS, not by me though). Sometimes this task freezes - I know because of time stamp printed on that status file - and my plan is to send a new file to the VPS, therefore allowing the task to continue. The program will have to be able to delete the remote file, then upload a substitute, without user intervention.

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Need to understand how to send and delete files on a VPS
« Reply #5 on: August 03, 2019, 02:48:15 pm »
pscp -pw yourPasswordHere C:\Users\testUser\Downloads\test.sh testUser@123.123.123.123:/home/testUser

pscp -pw (your password) (FILE) (WHERE) — as indicated above

I will try that right now!

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Need to understand how to send and delete files on a VPS
« Reply #6 on: August 03, 2019, 03:00:41 pm »
It worked, just as I wanted. Thanks, Sam! Trying to figure out how to delete the remote file now. It doesn't show how in options:

PuTTY Secure Copy client
Release 0.71
Usage: pscp [options] [user@]host:source target
       pscp [options] source [source...] [user@]host:target
       pscp [options] -ls [user@]host:filespec
Options:
  -V        print version information and exit
  -pgpfp    print PGP key fingerprints and exit
  -p        preserve file attributes
  -q        quiet, don't show statistics
  -r        copy directories recursively
  -v        show verbose messages
  -load sessname  Load settings from saved session
  -P port   connect to specified port
  -l user   connect with specified username
  -pw passw login with specified password
  -1 -2     force use of particular SSH protocol version
  -4 -6     force use of IPv4 or IPv6
  -C        enable compression
  -i key    private key file for user authentication
  -noagent  disable use of Pageant
  -agent    enable use of Pageant
  -hostkey aa:bb:cc:...
            manually specify a host key (may be repeated)
  -batch    disable all interactive prompts
  -no-sanitise-stderr  don't strip control chars from standard error
  -proxycmd command
            use 'command' as local proxy
  -unsafe   allow server-side wildcards (DANGEROUS)
  -sftp     force use of SFTP protocol
  -scp      force use of SCP protocol
  -sshlog file
  -sshrawlog file
            log protocol details to a file

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Need to understand how to send and delete files on a VPS
« Reply #7 on: August 03, 2019, 03:02:47 pm »
PSCP does not support deleting a file. psftp does. See the pscp download page to download psftp.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Need to understand how to send and delete files on a VPS
« Reply #9 on: August 03, 2019, 03:16:42 pm »
I did it with:

SHELL _HIDE "psftp login@123.123.123.123 -pw mypassword -b script.txt"

And inside script.txt:

cd /var/www/html
del file.txt

Thanks a ton, Sam.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Need to understand how to send and delete files on a VPS
« Reply #10 on: August 03, 2019, 03:45:56 pm »
Wait, I thought Sam was Pete! :D

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Need to understand how to send and delete files on a VPS
« Reply #11 on: August 03, 2019, 04:13:29 pm »
Wait, I thought Sam was Pete! :D

I just figured it was an abbreviation for Steve’s Awesome, Man!  :D
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Need to understand how to send and delete files on a VPS
« Reply #12 on: August 03, 2019, 05:40:16 pm »
Ooooooh ya carnsarn idjits haz me so confusicated, I'z can't evens shoot straight!!!

 - Sam... I means Pete... I means... 
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline FilipeEstima

  • Newbie
  • Posts: 63
    • View Profile
Re: Need to understand how to send and delete files on a VPS
« Reply #13 on: August 03, 2019, 07:05:44 pm »
I just figured it was an abbreviation for Steve’s Awesome, Man!  :D

Wait, is your name Steve? I'm sorry, I thought it was Sam McNeill, my mistake LOL