Community discussions

MikroTik App
 
helipos
Member Candidate
Member Candidate
Topic Author
Posts: 132
Joined: Sat Jun 25, 2016 11:32 am

SFTP uploads to remote SFTP server [SOLVED]

Mon Oct 12, 2020 2:32 pm

Hi all,
I'm having some serious issues uploading from SFTP to a remote SFTP server.
The remote server is Ubuntu server 20.04. Its in the same subnet.
I can see it connect in the SSH log files on the Ubuntu server but it seems to be closed by the Mikrotik instantly.

The Mikrotik complains of "failure: closing connection: <no such file> 192.168.1.8:22 (5) (6)"
> file print 
 # NAME                                               TYPE                                   SIZE CREATION-TIME       
 0 disk1                                                 disk                                        sep/16/2020 20:26:29
 1 text2.txt                                            .txt file                                     0 oct/11/2020 17:27:36
 2 log.0.txt                                            .txt file                                    7.9KiB oct/12/2020 06:46:48
 3 flash                                                  disk                                        oct/12/2020 06:46:48
 4 flash/auto-before-reset.backup        backup                                15.1KiB jan/01/1970 08:00:08
 5 flash/skins                                        directory                              jan/01/1970 08:00:07
 6 flash/pub                                          directory                              oct/07/2018 04:53:10

/tool fetch upload=yes url=sftp://192.168.1.8/ftp/text.txt user=ftpuser password=somepassword src-path=log.0.txt  src-address=192.168.1.20


status: failed
failure: closing connection: <no such file> 192.168.1.8:22 (5) (6)
This is the Ubuntu Server Logs.
Oct 12 19:16:24 web-services sshd[1357]: pam_unix(sshd:session): session opened for user ftpuser by (uid=0)
Oct 12 19:16:24 web-services systemd-logind[764]: New session 5 of user ftpuser.
Oct 12 19:16:24 web-services systemd[1372]: pam_unix(systemd-user:session): session opened for user ftpuser by (uid=0)
Oct 12 19:16:26 web-services sshd[1357]: pam_unix(sshd:session): session closed for user ftpuser
Oct 12 19:16:26 web-services systemd-logind[764]: Session 5 logged out. Waiting for processes to exit.
Oct 12 19:16:26 web-services systemd-logind[764]: Removed session 5.
I figure there must be some dumb as syntax error I have with the files, but for the life of me I can't see it. The Wiki unfortunately doesn't have examples of "uploading" using SFTP.
If anyone can give some pointers that would be greatly appreciated.
Last edited by helipos on Tue Oct 13, 2020 3:20 pm, edited 1 time in total.
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: SFTP uploads to remote SFTP server

Mon Oct 12, 2020 3:12 pm

The path on your server exists? You need a subdirectory"ftp" with write permission.
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11381
Joined: Thu Mar 03, 2016 10:23 pm

Re: SFTP uploads to remote SFTP server

Mon Oct 12, 2020 3:24 pm

The path set in /tool fetch url=... is rather absolute path from server's root (not from users home directory).
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: SFTP uploads to remote SFTP server

Mon Oct 12, 2020 3:42 pm

The path set in /tool fetch url=... is rather absolute path from server's root (not from users home directory).
That depends on the configuration. My sftp accounts are jailed into a chroot and limited to sftp only (with openssh's sftp-server). So for me the path is relative to the chroot directory.
 
helipos
Member Candidate
Member Candidate
Topic Author
Posts: 132
Joined: Sat Jun 25, 2016 11:32 am

Re: SFTP uploads to remote SFTP server

Mon Oct 12, 2020 4:22 pm

Spot on mkx.
Worked straight away.
Thanks eworm too, I'm sure when I get around to chrooting the user account I will use that.

For any other cut and paster like myself.
This worked.
tool fetch upload=yes url=sftp://192.168.1.8/media/Chronometer/ftp/text.txt user=ftpuser password=somepassword src-path=log.0.txt  src-address=192.168.1.20
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11381
Joined: Thu Mar 03, 2016 10:23 pm

Re: SFTP uploads to remote SFTP server

Mon Oct 12, 2020 6:03 pm

So for me the path is relative to the chroot directory.
So root is not absolute. OTOH you having chroot environment are fully aware of different breeds of paths while many users are not ... obviously.
 
helipos
Member Candidate
Member Candidate
Topic Author
Posts: 132
Joined: Sat Jun 25, 2016 11:32 am

Re: SFTP uploads to remote SFTP server [SOLVED]

Wed Oct 14, 2020 1:14 pm

Since I know slightly more than squat about Linux, this was the guide I used for setting up the SFTP server in case someone was wondering.

https://www.digitalocean.com/community/ ... untu-16-04
 
helipos
Member Candidate
Member Candidate
Topic Author
Posts: 132
Joined: Sat Jun 25, 2016 11:32 am

Re: SFTP uploads to remote SFTP server [SOLVED]

Tue Nov 29, 2022 12:15 am

Sorry, bit of thread mining here.
:global "SFTP_Result" [ tool fetch url="sftp://192.168.1.8/media/Chronometer/ftp/Mikrotik/Logs/$[/system identity get name].$Date.txt" user=someuser password=somepassword src-path=flash/log.0.txt upload=yes]
failure: invalid dst-path
:global "SFTP_Result" [ tool fetch url="sftp://192.168.1.8/media/Chronometer/ftp/Mikrotik/Logs/$[/system identity get name].$Date.txt" user=someuser password=somepassword src-path=log.0.txt upload=yes
    status: finished
  uploaded: 5004KiB
     total: 5004KiB
  duration: 5s
Just a note for all. If you make some noob error like getting the source directory wrong it will winge about the destination path being wrong, causing you to go crazy for a few days before you spot it.

Who is online

Users browsing this forum: BrianTax, coreshock, freemannnn, rplant and 61 guests