Delete directory and files with subdirectorys with ftp command line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: Delete directory and files with subdirectorys with ftp command line

#16 Post by Squashman » 22 Sep 2017 14:33

I know with the builtin Windows FTP.exe program you can actually pipe your commands to the program. Maybe you can do that with ncpftp as well.

Code: Select all

(echo open -u FtpAddress
echo FtpUsername
echo FtpPassword
echo mkdir AAA
echo cd AAA
echo mkdir 1A
echo mkdir 2B
echo mkdir 3C
echo cd ..
echo rm -r )|ncftp


Worth a try.

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: Delete directory and files with subdirectorys with ftp command line

#17 Post by r2du-soft » 23 Sep 2017 02:20

Squashman wrote:I know with the builtin Windows FTP.exe program you can actually pipe your commands to the program. Maybe you can do that with ncpftp as well.

Code: Select all

(echo open -u FtpAddress
echo FtpUsername
echo FtpPassword
echo mkdir AAA
echo cd AAA
echo mkdir 1A
echo mkdir 2B
echo mkdir 3C
echo cd ..
echo rm -r )|ncftp


Worth a try.



i tryed

Code: Select all

(echo open -u 138.201.29.24
echo test@update.iranisc.ir
echo testuL4O92t2Go~3
echo mkdir BBB
echo mkdir AAA
echo cd AAA
echo mkdir 1A
echo mkdir 2B
echo mkdir 3C
echo cd ..
echo rm -r )|ncftp

pause


FTP INFO:
Ftp Address: ftp://138.201.29.24
Ftp Username: test@update.iranisc.ir
Ftp Password: testuL4O92t2Go~3

but not work and i see this:

[img]
http://uupload.ir/files/vyi_ncftp.jpg
[/img]

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: Delete directory and files with subdirectorys with ftp command line

#18 Post by Compo » 23 Sep 2017 03:33

The NcFTP program supports command line arguments to log you in to the remote server but that's all; any other commands need to be entered interactively.

They also additionally created NcFTPGet, NcFTPPut and NcFTPLs to allow for an additional degree of non interactivity, but those won't cover your intended tasks

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: Delete directory and files with subdirectorys with ftp command line

#19 Post by r2du-soft » 23 Sep 2017 03:47

Thanks Compo
Nevertheless How can I do this?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Delete directory and files with subdirectorys with ftp command line

#20 Post by aGerman » 23 Sep 2017 07:16

Tried a combination of NcFTPLs and FTP

Code: Select all

@echo off &setlocal

set "uname=test@abc.def.ir"
set "passw=test12345"
set "hostn=ftp://abc.def.ir"
set "rootdir=Root"
set "lsfile=dirlist.txt"
set "ftpscript=test.ftp"

>"%lsfile%" (
  for /f "tokens=8 delims=;" %%i in (
    'ncftpls -u "%uname%" -p "%passw%" -R -m "%hostn%" ^| findstr /xrc:"type=dir;..*;[ ]*%rootdir%/[^;][^;]*"'
  ) do for /f "tokens=*" %%j in ("%%i") do echo %%j
)

>"%ftpscript%" (
  for /f "delims=" %%i in ("%hostn%") do echo open %%~nxi
  echo %uname%
  echo %passw%
  for /f "delims=" %%i in ('sort /r "%lsfile%"') do (
    echo cd %%i
    echo mdel *
    echo cd ..
    for %%j in ("%%i") do echo rmdir %%~nxi
    echo cd /
  )
  echo disconnect
  echo bye
)
ftp.exe -i -s:"%ftpscript%"


This seems to be working. At least I managed to successfully empty your Root folder even that I created a deeper structure with files beforehand.

Steffen

Post Reply