Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question #11

Closed
yangz1998 opened this issue Apr 4, 2021 · 2 comments
Closed

Question #11

yangz1998 opened this issue Apr 4, 2021 · 2 comments

Comments

@yangz1998
Copy link

I wrote a client program myself and successfully connected to your FTP server, but failed to create and delete folders on your server. Can you help me find out what went wrong? Grateful.

void del(char *usr_cmd) { time_t t_time; t_time=time(NULL); struct tm* tv=localtime(&t_time); char *cmd = strchr(usr_cmd,' '); char filename[1024]; if(cmd == NULL) { printf("command error!\n"); cout<<asctime(tv); return; } else { while(*cmd == ' ') cmd++; } if(cmd == NULL||cmd =="\0") { printf("command error!\n"); asctime(tv); return; } else { strncpy(filename,cmd,strlen(cmd)); filename[strlen(cmd)]='\0'; ftp_send_cmd("DELE ",filename,sock_control); ftp_get_reply(sock_control); } }

int ftp_send_cmd(const char *s1, const char *s2, int sock_fd) { time_t t_time; t_time=time(NULL); struct tm* tv=localtime(&t_time); char send_buf[256]; int send_err, len; if(s1) { strcpy(send_buf,s1); if(s2) { strcat(send_buf, s2); strcat(send_buf,"\r\n"); len = strlen(send_buf); send_err = send(sock_fd, send_buf, len, 0); } else { strcat(send_buf,"\r\n"); len = strlen(send_buf); send_err = send(sock_fd, send_buf, len, 0); } } if(send_err < 0) printf("send() error!\n"); cout<<asctime(tv); return send_err; }
error message:
FTP << DELE stats FTP >> 450 Unable to delete file

@FlorianReimold
Copy link
Member

I am not sure any more, but I think DELE will delete files, while RMD will remove directories. Deleting a non-empty directory will cause a client to open the directory, delete the files inside it and then delete the top-level directory.
Keep in mind, that having directories wasn't thing, when FTP was invented (1972, RFC 354), and thus the first FTP standard didn't support directories!

You can check out the "original" RFC 959 (which still only is an update for that ancient RFC 354). This RFC e.g. adds support for having files in directories.
https://tools.ietf.org/html/rfc959 (-> Page 32).

If you really want to implement an FTP Client on your own, I advise you to install an existing client, check what commands it is sending and replicate that behaviour.

@yangz1998
Copy link
Author

Thank you very much for your reply, I will try my best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants