[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to use Mdelete ?
Hello,
Before I attempt to answer your direct question, please let me give
background, because this is awfully hard to explain, otherwise.
When you type a command into an FTP client:
ftp> mdelete *
Are you are not sending the raw FTP protocol data to the server? Nope!
The FTP client is reading your command (mdelete) and intepreting it, and
it's taking care of sending the necessary FTP protocol data to the server.
This is also true of the PUT, GET, MPUT, MGET, DIR, LS, REN, etc FTP
commands. They aren't part of the FTP protocol... they're understood by
the FTP client, and the client sends the appropriate FTP protocol data
to the server needed to carry out that command.
The only exception to this is the 'QUOTE' command. Quote lets you send
a raw FTP protocol command to the server. Everything after the word
'QUOTE' is sent, as-is, to the server. The client doesn't make any
attempt to interpret/understand the text that follows the word quote.
So you could do this:
ftp> quote mdelete *
And it would fail spectacularly. Why? Because there IS NO MDELETE
COMMAND IN THE FTP PROTOCOL.
Try it yourself from a Windows Command Prompt:
C:\> ftp as400
Connected to xxxx.
220 Please log in
User (whatever): scott
Password:
230 SCOTT logged on.
ftp> quote mdelete *
500 Subcommand MDEL not valid
ftp> quit
Indeed, there's an option called "debug" that you can enable if you want
to see the actual FTP protocol that's being exchanged.
C:\> ftp as400
Connected to XXXXXXXXX.
220 Please log in
User (whatever): scott
331 Enter password.
Password:
230 SCOTT logged on.
ftp> debug 1
Debugging On .
ftp> cd /home/scott/scratch
---> CWD /home/scott/scratch
250-NAMEFMT set to 1.
250 "/home/scott/scratch" is current directory.
ftp> prompt 0
Interactive mode Off .
ftp> mdelete *
---> TYPE A
---> PORT 192,168,5,71,18,41
---> NLST *
---> TYPE A
200 Representation type is ASCII nonprint.
---> DELE file1
250 Deleted file /home/scott/scratch/file1
---> DELE file2
250 Deleted file /home/scott/scratch/file2
---> DELE file3
250 Deleted file /home/scott/scratch/file3
---> DELE file4
250 Deleted file /home/scott/scratch/file4
ftp>
In the preceding example, the lines beginning with ---> are the actual
FTP protocol data that the client is sending to the server. The lines
that begin with a number (which you always see) are the server's responses.
So when I send "cd /home/scott/scratch" it actually send the CWD command
in the FTP protocol data. (I could've used quote CWD to do the same thing.)
When I did an "mdelete" it sent "TYPE A" (ascii mode), then PORT to
establish which port the data should be sent on, then NLST *. NLST is
the FTP command to get a list of files in a directory -- the same thing
that FTPAPI sends when you call the FTP_list() subprocedure.
The NLST output occurs in a separate TCP session, so you don't see it on
the screen... but it involves the server sending a list of files to the
client. The files have one filename per line with no details of the
file included. The client saves this into an array.
Then you see the client sending a separate DELE command for each file
that it got in the list.
So when you run MDELETE, under the covers, it actually does two things,
it does a directory listing, and then sends a DELE command for every
file that was returned.
GASP! That's the same thing as calling FTP_list(), and then calling
FTP_delete() in a loop... isn't it?
So that's my recommendation to you (even though you apparently don't
want to do it, though you didn't say why) call FTP_list() followed by
FTP_delete().
If you are downloading the files before you receive them, I strongly
recommend calling FTP_list(), then calling FTP_get() and FTP_delete() in
the loop. Not only is it a little more efficient than doing an "mget"
and "mdelete", it's also much safer. (Any file added while you're
transferring the others won't be accidentally deleted.)
Good luck.
On 6/11/2011 4:38 AM, fm.fm@xxxxxxxxxxxxx wrote:
>
> Thanks for wonderful FTPAPI. I had just complete coding for Qanesava()
> and Qanersta() APIs with FTPAPI. I modified these sample programs from
> [1]http://systeminetwork.com/article/apis-example-save-application-api
> -and-exit-program to take the QANESAVA exit program data and stream to
> a IFS tempfile then ftp_put to FTP server by 1GB per file. The
> QANERSTA exit programs can restore ok.
>
>
> I have a problem about FTPAPI. I need MDELETE subcommand and had used
> by ftp_quote function. It seemed not support. But I manually entered
> the command mdelete or md something is work.
>
> 0:> MDELETE object*
>
> 0: 500 Syntax error, command unrecognized.
>
> Is there a solution to delete multiple files by using an asterisk
> generically, not ftp_dir then ftp_delete?
>
> Thank you and best regards.
>
> References
>
> 1. http://systeminetwork.com/article/apis-example-save-application-api-and-exit-program
>
>
>
>
> -----------------------------------------------------------------------
> This is the FTPAPI mailing list. To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> -----------------------------------------------------------------------
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------