# File Transfer - Using FTP LFTP commands

## FTP

### Commands

to resume a single file upload using the built-in ftp command you will need to know how many bytes of the file you have already sent. This should be accessible by using `ls`. Then you use the following sequence to restart your upload replacing `<#>` with the number of bytes already sent and `<filename>` with the filename you are uploading.

```
restart <#>
put <filename>
```

If the server allows it you should receive a message such as the following...

```
350 Restart position accepted (<#>).
150 Ok to send data.
```

This will resume your upload.

## LFTP

Using the LFTP command this allows you to restart a died ftp session

### Commands

The following command is the login to the server and go to the folder you are placing the file in

```shell
lftp user:pass@host/path/to/folder
```

<table border="1" id="bkmrk-lftp-user%3Apass%40host%2F-1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td><span style="color: rgb(241, 196, 15);">lftp user:pass@host/path/to/folder</span>  
cd ok, cwd=/path/to/folder   
lftp user@host:/path/to/folder&gt;<span style="color: rgb(241, 196, 15);"> reput file.ext</span>   
---&gt; TYPE I   
&lt;--- 200 Type set to I  
---&gt; SIZE file.ext  
&lt;--- 213 11842837120  
---&gt; PASV  
&lt;--- 227 Entering Passive Mode (10,211,14,15,220,70).  
---- Connecting data socket to (10.211.14.15) port 56390  
---- Data connection established  
---&gt; ALLO 20769244058  
&lt;--- 202 No storage allocation necessary  
---&gt; REST 11842837120  
&lt;--- 350 Restarting at 11842837120. Send STORE or RETRIEVE to initiate transfer  
---&gt; STOR file.ext  
&lt;--- 150 Opening BINARY mode data connection for file.ext  
`file.ext' at 6756302848 (32%) 31.50M/s eta:7m \[Sending data\] </td></tr></tbody></table>

This command is to restart the failed FTP replace the "file.txt" with your file

```
reput file.txt
```

After a quick search, there's a command line program called `lfvi sftp` that provides ftp mirroring functionality.

Adapted from a guide [here](http://sina.salek.ws/content/how-mirrorsync-remote-ftp-folder-local-folder "LFTP"), something like this should do the trick:

```bash
#!/bin/bash
HOST='address.co.uk'
USER='myuser'
PASS='mypass'
TARGETFOLDER='/public_html/java/desktop/'
SOURCEFOLDER='deploy/'

lftp -f "
open $HOST
user $USER $PASS
lcd $SOURCEFOLDER
mirror --reverse --delete --verbose $SOURCEFOLDER $TARGETFOLDER
bye
"
```

I'd suggest you'd do it without the `--delete` until you're sure you've got the arguments right!