23

I am logged in on a server (using Putty). from there I'm connecting using FTP to another server. I want to copy several folders from the first server to the second server using mput.

Like:

ftp> mput folder1 folder2 folder3

But I get "folder1: not a plain file."...and so on. Each of these folders have subfolders, files (some binary, some not).

How can I accomplish what I want without zipping the stuff and then transfer?

7ochem
  • 280
  • 1
  • 3
  • 12

5 Answers5

22

Command line FTP is pretty primitive.

You can't recursively send files/folders towards a remote site.

If you want to recreate a directory structure on the remote side the same as the local, you need to manually mkdir each path and use mput * to send everything in that directory to the remote side.

Two options to make this easier:

  1. Stop using the primitive FTP command (ncftp is a good alternative)

  2. Use tar to tar up the folders, send the file and extract on the far side.

Neptilo
  • 103
  • 4
Philip Reynolds
  • 9,799
  • 1
  • 34
  • 33
  • 1
    +1 for tar->put->untar – dave Nov 04 '17 at 23:06
  • 1
    -1 Because question asks "How can I accomplish what I want without zipping the stuff and then transfer?", implying that the person does not have shell access to the remote machine. – Steen Schütt Nov 24 '17 at 10:50
18

I made a bash script:

#!/bin/bash
ftp_site=ftp.yoursite.net
username=my_user_name
passwd=my_password
remote=/path/to/remote/folder
folder=$1
cd /path/to/local/folder/$folder
pwd
ftp -in <<EOF
open $ftp_site
user $username $passwd
mkdir $remote/$folder
cd $remote/$folder
mput *
close
bye

and called it with

find . -type d -exec ./recursive-ftp.sh {} \;

seems to work.

Stein Åsmul
  • 2,616
  • 6
  • 26
  • 38
11

This is not possible with the normal ftp program as mput does not use recursion. You could use ncftp and then call 'mput -r folder'.

Best wishes, Fabian

halfdan
  • 704
  • 4
  • 6
0

open powershell cd to the directory you want to upload run the following commands:

1. gci -r | % {if ($_.PSIsContainer) {$t = $((($_.fullname -split "\\")[$(((pwd) -split "\\").length)..200]) -join "/"); "mkdir ""$t""`r`nmput ""$t/*"" ""$t"""}} | sc .\mput_all
2. notepad .\mput_all

Paste the results into your ftp window. Enjoy. Also don't forget to add mput * to transfer all the files from the base directory.

0

Secure Copy scp has a -r recursive flag that you might find useful.

Michael
  • 11