| 148 | } |
| 149 | |
| 150 | func (c *Client) WriteFile(ctx context.Context, remotePath string, content io.Reader) error { |
| 151 | u, err := url.Parse(c.BaseURL) |
| 152 | if err != nil { |
| 153 | return err |
| 154 | } |
| 155 | parts := strings.Split(strings.Trim(remotePath, "/"), "/") |
| 156 | u.Path = path.Join(u.Path, strings.Join(parts, "/")) |
| 157 | resp, err := c.doRequest(ctx, WebdavMethodPut, u.String(), content) |
| 158 | if err != nil { |
| 159 | return err |
| 160 | } |
| 161 | defer resp.Body.Close() |
| 162 | |
| 163 | if resp.StatusCode >= 200 && resp.StatusCode < 300 { |
| 164 | return nil |
| 165 | } |
| 166 | return fmt.Errorf("PUT: %s", resp.Status) |
| 167 | } |
| 168 | |
| 169 | // ListDir lists files and directories in the given path |
| 170 | func (c *Client) ListDir(ctx context.Context, dirPath string) ([]Response, error) { |