>
>
>
>
When transferring large files via FTP in virtualized environments (especially between Linux VMs and external FTP servers), the TCP connection timeout issue typically stems from these technical factors:
>
>
-
>
- TCP keepalive settings not being properly configured
- Network Address Translation (NAT) timeout thresholds being too aggressive
- Firewall or router dropping idle connections
- VM network adapter configurations interfering with long-running transfers
>
>
>
>
>
>
>
>
>
>
>
>
>
Before implementing solutions, verify where the timeout occurs:
>
>
> ># Check current TCP keepalive settings > >cat /proc/sys/net/ipv4/tcp_keepalive_time > >cat /proc/sys/net/ipv4/tcp_keepalive_intvl > >cat /proc/sys/net/ipv4/tcp_keepalive_probes > ># Monitor established connections > >watch -n 5 "netstat -tn | grep ESTABLISHED" > >
>
>
>
>
1. Adjust TCP Keepalive Parameters
>
>
Temporarily modify these values during your FTP session:
>
>
> ># Set keepalive to 300 seconds (5 minutes) > >echo 300 > /proc/sys/net/ipv4/tcp_keepalive_time > >echo 60 > /proc/sys/net/ipv4/tcp_keepalive_intvl > >echo 5 > /proc/sys/net/ipv4/tcp_keepalive_probes > >
>
>
For permanent changes, add to /etc/sysctl.conf
:
>
>
> >net.ipv4.tcp_keepalive_time = 300 > >net.ipv4.tcp_keepalive_intvl = 60 > >net.ipv4.tcp_keepalive_probes = 5 > >
>
>
2. Use FTP Client with Built-in Keepalive
>
>
Configure ncftpget
with keepalive:
>
>
> >ncftpget -R -v -T -k 60 ftp://user:pass@server.com/path/to/largefile > >
>
>
Where -k 60
sends keepalive packets every 60 seconds.
>
>
3. Alternative: lftp with Robust Transfer
>
>
lftp
handles interrupted transfers better:
>
>
> >lftp -e "set net:timeout 30; set net:max-retries 10; set net:reconnect-interval-base 60; \ > >mirror --use-pget-n=5 /remote/path/ /local/path/; quit" ftp://user:pass@server.com > >
>
>
4. Router/Firewall Configuration
>
>
If you control the network equipment:
>
>
> ># For Linux iptables: > >iptables -I INPUT -p tcp --dport 21 -m state --state ESTABLISHED,RELATED -j ACCEPT > >iptables -I INPUT -p tcp --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT > ># Increase NAT timeout (Cisco example): > >ip nat translation timeout 86400 > >
>
>
>
>
For very large files (>1GB), adjust window scaling:
>
>
> ># Linux VM settings > >echo "4096 87380 4194304" > /proc/sys/net/ipv4/tcp_rmem > >echo "4096 87380 4194304" > /proc/sys/net/ipv4/tcp_wmem > >
>
>
>
>
After implementing changes, verify with:
>
>
> ># Show current TCP parameters > >sysctl -a | grep tcp > ># Test transfer with verbose output > >curl -v -O ftp://server.com/largefile.zip > >
>
>
When transferring large files via FTP to a Linux VM, that dreaded timeout error "Could not read reply from control connection -- timed out"
typically appears mid-transfer. Based on your setup (VMWare/VirtualBox with bridged/NAT networking), we're likely dealing with TCP keepalive issues at multiple layers.
The core issue stems from intermediate devices (routers/NAT) dropping idle connections. Here's how to verify and configure keepalive settings:
# Check current keepalive settings (Linux VM) cat /proc/sys/net/ipv4/tcp_keepalive_time cat /proc/sys/net/ipv4/tcp_keepalive_intvl cat /proc/sys/net/ipv4/tcp_keepalive_probes # Temporary settings (survives until reboot) sudo sysctl -w net.ipv4.tcp_keepalive_time=300 sudo sysctl -w net.ipv4.tcp_keepalive_intvl=60 sudo sysctl -w net.ipv4.tcp_keepalive_probes=5
For ncftpget
, add these parameters:
ncftpget -R -T -t 300 -d /path/to/debug.log ftp://user:pass@host/largefile.ext
Where:
-t 300
sets timeout to 300 seconds
-T
enables auto-resume
-d
enables debug logging
lftp
handles interrupted transfers better:
lftp -e "set net:timeout 300; set net:max-retries 5; \ set net:reconnect-interval-base 30; \ get /remote/largefile.ext -o localfile.ext; quit" ftp://user:pass@host
Add these registry tweaks to prevent host OS interference:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] "KeepAliveTime"=dword:000493e0 "KeepAliveInterval"=dword:00007530 "MaxDataRetransmissions"=dword:0000000a
For VMWare/VirtualBox, ensure these VMX settings exist:
ethernet0.connectionType = "bridged" ethernet0.virtualDev = "vmxnet3" isolation.tools.ghi.longrunning.enable = "TRUE"
When all else fails, consider these more resilient protocols:
# Using rsync over SSH rsync -avzP --timeout=300 user@host:/path/to/largefile.ext . # HTTP with aria2 (supports resume) aria2c -x16 -s16 -k1M --timeout=300 http://host/largefile.ext
Use these commands to identify where packets get dropped:
# Continuous ping test ping -t ftp.host.com # TCP connection test sudo tcpdump -i eth0 'host ftp.host.com and port 21' # Check for MTU issues tracepath -n ftp.host.com